package chapter_8;

import chapter_7.Dog;

import java.util.*;

public class Test2 {
    public static void main(String[] args) {
        List c = new ArrayList();
        Dog dog1 = new Dog("小黑", 5, "黑色");
        Dog dog2 = new Dog("小黑", 4, "黑色");
        Dog dog3 = new Dog("小黑", 6, "黑色");
        c.add(dog1);
        c.add(dog2);
        c.add(dog3);
//        System.out.println(c);
//        Collections.sort(c);
//        System.out.println("-----------------------------------------------");
//        System.out.println(c);
        //第一种遍历 普通for
        for (int i = 0; i < c.size(); i++) {
            System.out.println(c.get(i));
        }

        //迭代器遍历
        Iterator iterator = c.iterator();
        while(iterator.hasNext()){
            System.out.println(iterator.next());
        }

        //增强for循环
        for (Object o : c) {
            System.out.println(o);
            c.remove(new Dog("小黑",5,"黑色"));
        }

    }
}
